package it.davial.mgwt.client.activities;

import it.davial.mgwt.client.event.ActionEvent;
import it.davial.mgwt.client.event.ActionNames;

import org.bsc.mgwt.client.widget.ProgressHeaderIndicator;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.googlecode.mgwt.dom.client.event.tap.TapEvent;
import com.googlecode.mgwt.dom.client.event.tap.TapHandler;
import com.googlecode.mgwt.mvp.client.MGWTAbstractActivity;
import com.googlecode.mgwt.ui.client.event.ShowMasterEvent;

public class BaseActivity extends MGWTAbstractActivity {

	private final BaseView detailView;
	private final String eventId;
	protected ProgressHeaderIndicator progressHeader = new ProgressHeaderIndicator();

	public BaseActivity(BaseView detailView, String eventId) {
		this.detailView = detailView;
		this.eventId = eventId;

	}

	@Override
	public void start(AcceptsOneWidget panel, final EventBus eventBus) {
		addHandlerRegistration(detailView.getMainButton().addTapHandler(new TapHandler() {

			@Override
			public void onTap(TapEvent event) {
				eventBus.fireEvent(new ShowMasterEvent(eventId));

			}
		}));

		addHandlerRegistration(detailView.getBackbutton().addTapHandler(new TapHandler() {

			@Override
			public void onTap(TapEvent event) {
				ActionEvent.fire(eventBus, ActionNames.BACK);

			}
		}));

	}

}
